import Vue from "vue";
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        num: 0
    },
    getters: {
        oddOrEven(state){
            return 1 & state.num ? '奇数' : '偶数';
        }
    },
    actions: {
        asyncAdd(store){
            setTimeout(() => {
                store.commit('ASYNCADD');
            },1000)
        }
    },
    mutations: {
        ADD(state){
            state.num += 1;
        },
        REDUCE(state){
            state.num -= 1;
        },
        ODDNUMBERADD(state){
            1 & state.num ? state.num += 1 : '';
        },
        ASYNCADD(state){
            state.num += 1; 
        }
    }
})